<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="UTF-8" />
    <meta name="author" content="xmy6364">
    <meta name="description" content="想要成为大佬">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />

    <link rel="shortcut icon" href="/assets/favicon.ico" type="image/x-icon">
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@600&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/highlight.js/10.5.0/styles/default.min.css">
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/highlight.js/10.5.0/styles/github-gist.min.css">
    <link rel="stylesheet" href="/assets/lib/css/font-awesome.min.css">
    <link rel="stylesheet" href="/assets/css/layout.css" />
    <script defer src="https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.6/clipboard.min.js"></script>
    <script defer src="/assets/js/copyCode.js"></script>
    <script defer src="/assets/js/backTop.js"></script>
    <script defer src="/assets/js/tool.js"></script>

    
  <link rel="stylesheet" href="/assets/css/page.css" />
  <link rel="stylesheet" href="/assets/css/sidebar.css" />
  <link rel="stylesheet" href="/assets/css/footer.css" />
  <link rel="stylesheet" href="/assets/css/post.css" />
  <script defer src="/assets/js/backHome.js"></script>
  <script defer src="/assets/js/toc.js"></script>
  <script defer src="/assets/js/copyright.js"></script>


    <title>搭建hexo静态博客</title>
  </head>
  <body>
    <div class="container">
      <aside>
        
  <div class="sidebar">
  <header>梦的博客</header>
  <div class="info">
    <div class="avatar">
      <img src="https://cdn.jsdelivr.net/gh/xmy6364/blog-image/img/pixelartoc_1.png" alt="头像">
    </div>
    <div class="author">xmy6364</div>
    <div class="description">想要成为大佬</div>
    <div class="about">
      <a href="/about">about me.</a>
    </div>
  </div>
  <div class="links">
    <ul>
    
      <li class="links-item">
        <a href="https://github.com/xmy6364" target="_blank">
          <i class="fa fa-github-alt" aria-hidden="true"></i>
        </a>
      </li>
    
      <li class="links-item">
        <a href="tencent://message/?uin=1176281967" target="_blank">
          <i class="fa fa-qq" aria-hidden="true"></i>
        </a>
      </li>
    
    </ul>
  </div>
  <nav>
    <ul>
    
      <li class="nav-item">
        <a href="/archives">
          <span class="nav-item__count">31</span>
          <span class="nav-item__label">归档</span>
        </a>
      </li>
    
      <li class="nav-item">
        <a href="/categories">
          <span class="nav-item__count">1</span>
          <span class="nav-item__label">分类</span>
        </a>
      </li>
    
      <li class="nav-item">
        <a href="/tags">
          <span class="nav-item__count">45</span>
          <span class="nav-item__label">标签</span>
        </a>
      </li>
    
    </ul>
  </nav>
  <div class="catalogue" id="catalogue"></div>
</div>

      </aside>
      <main>
        
  <div class="post">
    <div class="post-front">
      <h1 class="post-front__title">搭建hexo静态博客</h1>
      <div class="post-front__desc">
        
        <p class="post-front__desc-date">
          <i class="fa fa-calendar" aria-hidden="true"></i>
          2019/08/31 09:13:23
        </p>
        
        
        <p class="post-front__desc-category">
          <i class="fa fa-folder-o" aria-hidden="true"></i>
          <a href="/categories/技术">
            技术
          </a>
        </p>
        
          <div class="post-front__desc-tags">
          
          <a href="/tags/hexo">
            <i class="fa fa-tag" aria-hidden="true"></i>
            hexo
          </a>
          
        </div>
      </div>
    </div>
    <div class="post-content">
      <nav id="toc" class="toc"><ol><li><a href="#需要的工具">需要的工具</a></li><li><a href="#正式开始">正式开始</a></li><li><a href="#添加新的文章">添加新的文章</a></li></ol></nav><p>使用hexo搭建博客，并将博客部署到github</p>
<h2 id="需要的工具">需要的工具</h2>
<ul>
<li><a href="https://nodejs.org/zh-cn/">Node.js</a></li>
<li><a href="https://github.com/waylau/git-for-win">Git</a></li>
<li>一个Github账号</li>
</ul>
<h2 id="正式开始">正式开始</h2>
<ol>
<li>在任意目录下新建一个文件夹，如blog，在该文件夹下右键打开git bash here，执行<code>npm install -g hexo-cli</code>，安装hexo</li>
<li>执行<code>hexo init</code></li>
<li>执行<code>npm install</code></li>
<li>根据提示依次执行<code>npm audit fix</code>和<code>npm audit fix --force</code></li>
<li>执行<code>hexo g</code>，生成博客</li>
<li>执行<code>hexo s</code>后，可以在 http://localhost:4000 上预览博客</li>
<li>在github上新建一个仓库，命名为username.github.io，其中username必须为你github的用户名</li>
<li>执行<code>npm install hexo-deployer-git --save</code>，安装deployer-git，用来将hexo推送到github</li>
<li>修改配置文件：在文件夹中找到并打开<code>_config.yml</code>文件，将文件末尾的deploy部分更改如下，repo: 后填写你新建的github仓库的地址。<strong>注意: 请使用英文冒号以及冒号后要有空格</strong></li>
</ol>
<pre class="hljs"><code><button class="copy-btn" type="button" data-clipboard-action="copy" data-clipboard-target="#copy1620560208382">复制</button><span class="hljs-attr">deploy:</span>
  <span class="hljs-attr">type:</span> <span class="hljs-string">git</span>
  <span class="hljs-attr">repo:</span> <span class="hljs-string">https://github.com/xmy6364/xmy6364.github.io.git</span>
  <span class="hljs-attr">branch:</span> <span class="hljs-string">master</span>
<b class="name">yml</b></code><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></pre><textarea style="position: absolute;top: -9999px;left: -9999px;z-index: -9999;" id="copy1620560208382">deploy:
  type: git
  repo: https://github.com/xmy6364/xmy6364.github.io.git
  branch: master
</textarea>
<ol start="10">
<li>分别执行<code>hexo clean</code>，<code>hexo g</code>，<code>hexo d</code>，即可在 https://username.github.io *(username为你的用户名)*中看到自己的博客</li>
</ol>
<h2 id="添加新的文章">添加新的文章</h2>
<ol>
<li>执行<code>hexo new &quot;文章标题&quot;</code>，会在<code>\source\_posts</code>下生成一个md文件，在该文件中编辑文章即可</li>
<li>写完文章后，分别执行<code>hexo g</code>，<code>hexo d</code>，即可将文章发布成功，如果网站上没有出现文章可以稍等一会儿再刷新。(<code>hexo clean</code>在发布和修改文章时可以不执行，在修改主题后需要执行)</li>
</ol>

    </div>
    
  </div>

        <footer>
        
  <div class="footer">
  
  <div class="theme">
    博客主题为 <a href="https://github.com/xmy6364/CoinRailgun">CoinRailgun</a> 默认主题
  </div>
  <div class="copyright">
    <span>© 2019-2021 xmy6364.</span>
    <span>Powered by <a href="https://github.com/xmy6364/CoinRailgun">CoinRailgun</a></span>
  </div>
</div>

        </footer>
      </main>
    </div>
  </body>
</html>
